package com.ruoyi.vip.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.vip.domain.Vip;
import com.ruoyi.vip.service.IVipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员信息Controller
 *
 * @author ruoyi
 * @date 2021-04-19
 */
@RestController
@RequestMapping("/vip/vip")
public class VipController extends BaseController
{
    @Autowired
    private IVipService vipService;

    /**
     * 查询会员列表
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:list')")
    @GetMapping("/list")
    public TableDataInfo list(Vip vip)
    {
        startPage();
        List<Vip> list = vipService.selectVipList(vip);
        return getDataTable(list);
    }

    /**
     * 导出会员列表
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:export')")
    @Log(title = "导出会员", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Vip vip)
    {
        List<Vip> list = vipService.selectVipList(vip);
        ExcelUtil<Vip> util = new ExcelUtil<Vip>(Vip.class);
        return util.exportExcel(list, "vip");
    }

    /**
     * 获取会员详细信息
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:query')")
    @GetMapping(value = "/{vipId}")
    public AjaxResult getInfo(@PathVariable("vipId") Long vipId)
    {
        return AjaxResult.success(vipService.selectVipById(vipId));
    }

    /**
     * 新增会员
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:add')")
    @Log(title = "新增会员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Vip vip)
    {
        return toAjax(vipService.insertVip(vip));
    }

    /**
     * 修改会员
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:edit')")
    @Log(title = "修改会员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Vip vip)
    {
        return toAjax(vipService.updateVip(vip));
    }

    /**
     * 删除会员
     */
    @PreAuthorize("@ss.hasPermi('vip:vip:remove')")
    @Log(title = "删除会员", businessType = BusinessType.DELETE)
	@DeleteMapping("/{vipIds}")
    public AjaxResult remove(@PathVariable Long[] vipIds)
    {
        return toAjax(vipService.deleteVipByIds(vipIds));
    }
}
